package com.wfh.parse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import java.util.List;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.wfh.bean.BannerBean;

public class T_Banner implements TransForm{
	
	public List<BannerBean> pareseJsonArray(String json){
		List<BannerBean> list=new ArrayList<BannerBean>();
		try {
			JSONObject jsonObject = new JSONObject(json);
			JSONArray arr=jsonObject.getJSONArray("banners");
			for(int i=0;i<arr.length();i++){
				BannerBean bean=new BannerBean();
				bean.setBak(arr.getJSONObject(i).getString("bak"));
				bean.setBanner_id(arr.getJSONObject(i).getString("banner_id"));
				bean.setImg(arr.getJSONObject(i).getString("img"));
				bean.setPosition(arr.getJSONObject(i).getString("position"));
				bean.setReview(arr.getJSONObject(i).getString("review"));
				bean.setShop_id(arr.getJSONObject(i).getString("shop_id"));
				bean.setStatus(arr.getJSONObject(i).getString("status"));
				bean.setUrl(arr.getJSONObject(i).getString("url"));
				list.add(bean);
			}
			//Log.i("list",list.size()+"");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return list;
	}

	@Override
	public Map<String,String> pareseJsonObject(String json) {
		Map<String,String> map=new HashMap<String,String>();
		try {
			JSONObject jsonObject = new JSONObject(json);
			if(jsonObject.getString("ret").equals("0")){
				map.put("ret", jsonObject.getString("ret"));
				return map;
			}
			map.put("ret", jsonObject.getString("ret"));
			map.put("module", jsonObject.getString("module"));
			map.put("version", jsonObject.getString("version"));
			map.put("shop_name", jsonObject.getJSONObject("shop_info").getString("shop_name"));
			map.put("shop_id", jsonObject.getString("shop_id"));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public Object pareseJsonBean(String json) {
		return null;
	}
	
}
